package com.dhcc.config.response;

import java.io.Serializable;


public class ResponseResult<T> {

    /**
     * response timestamp.
     */
    private long timestamp;

    /**
     * response code, 200 -> OK.
     */
    private String status;

    /**
     * response message.
     */
    private String message;

    /**
     * response data.
     */
    private T data;

    /**
     * response success result wrapper.
     *
     * @param <T> type of data class
     * @return response result
     */
    public static <T> ResponseResult<T> success() {
        return success(null);
    }

    /**
     * response success result wrapper.
     *
     * @param data response data
     * @param <T>  type of data class
     * @return response result
     */
    public static <T> ResponseResult<T> success(T data) {
    	ResponseResult<T> responseResult = new ResponseResult<T>();
    	responseResult.setData(data);
    	responseResult.setMessage(ResponseStatus.SUCCESS.getDescription());
    	responseResult.setStatus(ResponseStatus.SUCCESS.getResponseCode());
    	responseResult.setTimestamp(System.currentTimeMillis());
    	return responseResult;
    }

    /**
     * response error result wrapper.
     *
     * @param message error message
     * @param <T>     type of data class
     * @return response result
     */
    public static <T extends Serializable> ResponseResult<T> fail(String message) {
        return fail(null, message);
    }

	/**
     * response error result wrapper.
     *
     * @param data    response data
     * @param message error message
     * @param <T>     type of data class
     * @return response result
     */
    public static <T> ResponseResult<T> fail(T data, String message) {
    	ResponseResult<T> responseResult = new ResponseResult<T>();
    	responseResult.setData(data);
    	responseResult.setMessage(message);
    	responseResult.setStatus(ResponseStatus.FAIL.getResponseCode());
    	responseResult.setTimestamp(System.currentTimeMillis());
    	return responseResult;
    }

	public long getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(long timestamp) {
		this.timestamp = timestamp;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

}
